namespace EyeOpen.BuildLab.Build
{
	using System;

	using EyeOpen.Build;
	using EyeOpen.Dependency;
	using EyeOpen.Io;

	public class BuildDependencyRegister 
		: IDependencyRegister
	{
		public object GetInstanceOrDefault(Type type)
		{
			if (type == typeof(IMsBuildTask))
			{
				return GetType<IMsBuildTask>();
			}
			
			if (type == typeof(ICopyTask))
			{
				return GetType<ICopyTask>();
			}

			if (type == typeof(IRemoveProjectsFromSolutionFileTask))
			{
				return GetType<IRemoveProjectsFromSolutionFileTask>();
			}

			if (type == typeof(IFile))
			{
				return GetType<IFile>();
			}

			return
				null;
		}

		private T GetType<T>()
		{
			var type = typeof(T);

			object obj = null;

			if (type == typeof(IFile))
			{
				obj = new FileWrapper();
			}
			else if (type == typeof(IMsBuildTask))
			{
				obj = new MsBuildTask();
			}
			else if (type == typeof(ICopyTask))
			{
				obj = new CopyTask(GetType<IFile>());
			}
			else if (type == typeof(IRemoveProjectsFromSolutionFileTask))
			{
				obj = new RemoveProjectsFromSolutionFileTask(GetType<IFile>());
			}

			if (obj != null)
			{
				return (T)obj;
			}

			return default(T);
		}
	}
}